﻿/**********************************************************************
 * @file   FITKCGNSIOInterface.h
 * @brief  CGNS IO接口
 * @author liuzhonghua (liuzhonghuaszch@163.com)
 * @date   2024-09-19
 *********************************************************************/

#include "FITKCGNSIOAPI.h"
#include "FITK_Kernel/FITKCore/FITKCoreMacros.h"
#include "FITK_Kernel/FITKCore/FITKAbstractObjectContainer.hpp"
#include "FITK_Kernel/FITKAppFramework/FITKComponentInterface.h"
#include <QObject>

ForwardDeclarNS(Interface, FITKAbstractIO);

namespace Interface {
    class FITKUnstructuredFluidMeshVTK;
}
namespace IO
{
    /**
     * @brief  CGNS 读写接口 
     * @author liuzhonghua (liuzhonghuaszch@163.com)
     * @date   2024-09-19
     */
    class FITKCGNSIOAPI FITKCGNSIOInterface : public QObject, public AppFrame::FITKComponentInterface
    {
        Q_OBJECT
    public:
        /**
         * @brief  构造函数
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-09-19
         */
        FITKCGNSIOInterface() = default;
        /**
         * @brief  析构函数
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-09-19
         */
        ~FITKCGNSIOInterface() = default;
        /**
         * @brief 设置文件名称
         * @param fileName 文件名称
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-09-19
         */
        void setFileName(const QString& fileName);
        /**
         * @brief  获取组件名称
         * @return 组件名称
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-09-19
         */
        QString getComponentName() override;
        /**
         * @brief  执行组件
         * @return 执行结果
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-09-19
         */
        bool exec(const int indexPort) override;
        /**
         * @brief  设置网格数据存放对象
         * @param  mesh 网格数据对象
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-09-19
         */
        void setMeshObj(Interface::FITKUnstructuredFluidMeshVTK* mesh);
        /**
         * @brief 获取是否执行成功标记
         * @return bool
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-09-19
         */
        bool isSuccess();
        /**
         * @brief 是否在执行中
         * @return true 执行中 false未在执行
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-09-19
         */
        bool isRunning();
        /**
         * @brief 设置是否在独立的线程运行。默认true，为在独立线程执行
         * @param r 是否在独立线程运行
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-09-19
         */
        void setRunInThread(bool r = true);

    signals:
        /**
         * @brief 读取线程结束发送信号
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-09-19
         */
        void ioThreadFinishedSig();

    private slots:
        /**
         * @brief 读取线程结束处理槽函数
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-09-19
         */
        void ioThreadFinishedSlot();

    private:
        /**
         * @brief  文件名
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-09-19
         */
        QString m_fileName{};
        /**
         * @brief  网格数据对象
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-09-19
         */
        Interface::FITKUnstructuredFluidMeshVTK* m_Mesh{};
        /**
         * @brief 读写线程
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-03-04
         */
        Core::FITKAbstractObjectContainer<Interface::FITKAbstractIO> m_io{ nullptr };
        /**
         * @brief 是否执行成功标记
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-09-19
         */
        bool m_success{ false };
        /**
         * @brief 是否在线程运行
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-03-04
         */
        bool m_runInThread{ true };
    };

}